unit modeloDadosU;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.Buttons, Vcl.ExtCtrls,
  Data.DB;

type
  TfrmModelosDados = class(TForm)
    gbDados: TGroupBox;
    ds: TDataSource;
    tpControle: TPanel;
    btnCancelar: TBitBtn;
    btnSalvar: TBitBtn;
    btnFechar: TBitBtn;
    procedure btnFecharClick(Sender: TObject);
    procedure btnCancelarClick(Sender: TObject);
    procedure btnSalvarClick(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure dsStateChange(Sender: TObject);
    procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmModelosDados: TfrmModelosDados;

implementation

{$R *.dfm}

uses dmU;

procedure TfrmModelosDados.btnCancelarClick(Sender: TObject);
begin
ds.DataSet.Cancel;
end;

procedure TfrmModelosDados.btnFecharClick(Sender: TObject);
begin
self.Close;
end;

procedure TfrmModelosDados.btnSalvarClick(Sender: TObject);
begin
 ds.DataSet.Post;
end;


procedure TfrmModelosDados.dsStateChange(Sender: TObject);
begin
if ds.state in [dsinsert, dsedit] then begin
btnSalvar.enabled := true;
btnCancelar.enabled := true;
end
else begin
   btnSalvar.enabled := false;
   btnCancelar.enabled := false;
end;
 end;
procedure TfrmModelosDados.FormClose(Sender: TObject; var Action: TCloseAction);
begin
action:=caFree;
self := nil;
end;

procedure TfrmModelosDados.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
 if key = vk_escape then
begin
self.close;
end;
end;

end.
